﻿using System;
using System.Collections.Generic;

namespace SWSP.Management.ServerObjects
{
    public abstract class Column
    {
        #region Ctor

        /// <summary>
        /// Initializes a new Column class
        /// </summary>
        public Column(string columnName)
        {
            this.Name = ParseColumnName(columnName);
        }

        public Column(string tableName, string columnName)
        {
            this.Name = ParseColumnName(columnName);
        }

        #endregion

        #region Public Properties

        public string DataType
        {get; internal set;}
        
        public bool Nullable
        { get; internal set; }

        public bool Identity
        { get; internal set; }

        public string Name
        { get; internal set; }

        #endregion

        #region Public Methods

        public string ParseColumnName(string columnName)
        {
            string name = string.Empty;

            // Remove [] branches
            foreach (char s in columnName)
            {
                if (s != '[' && s != ']')
                    name += s;
            }

            // Remove dbo before the name
            if (name.StartsWith("dbo."))
                return name.Remove(0, 4);
            else
                return name;
        }

        #endregion

    }
}
